#include "base_globals.h"
#include <windows.h>


EBaseError conf_init()
{
    HANDLE handle = CreateFileA("conf.txt", GENERIC_READ,
        FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

    LARGE_INTEGER size; 
    char* buf = NULL;
    DWORD readBytes = 0;
    char delim[] = "\r\n";
    char* next_token = NULL;
    char* token;

    // Set the default parameter for conf
    Globals* g = globals();
    g->conf.log_level = LOG_DEBUG;

    if (handle == NULL) {
        return BASE_SUCCEED;
    }
    if (GetFileSizeEx(handle, &size) == 0) {
        return BASE_READ_CONF_FAILED;
    }
    buf = (char*)malloc(size.LowPart);
    if (!ReadFile(handle, buf, size.LowPart, &readBytes, 0)) {
        return BASE_READ_CONF_FAILED;
    }


    token = strtok_s(buf, delim, &next_token);
    printf(strToken);
    while (true) {
        token = strtok_s(NULL, delim, &next_token);
         printf(strToken);
    }

    CloseHandle(handle);
    
    return BASE_SUCCEED;
}